<?php include "./pc/view/header.inc.htm"; ?>

<div class="panel_body margin">
	<dl class="row vtop" id="post_create_dl">
		<dt>
			<img src="<?php echo $user['avatar_url']; ?>" class="avatar" />
		</dd>
		<dd>
			<dl class="row">
				<dt class="left small">
					<b class="light"><?php echo $user['username']; ?></b>　
					<i class="light"><?php echo $user['create_date_fmt']; ?></i>
				</dt>
				<dd class="right">
				</dd>
			</dl>
			<div class="post">
				<form method="POST" id="post_create_form" action="post-create-<?php echo $tid; ?>.htm" class="form margin">
					<div><textarea id="post_message" name="message" placeholder="内容" style="width: 100%; height: 300px;"></textarea></div>
					<dl class="row margin">
						<dt>
							<button type="button" loading-text="正在提交" class="big blue" style="width: 208px;">发帖</button>
						</dt>
						<dd class="right">
						</dd>
					</dl>
				</form>
			</div>
		</dd>
	</dl>
</div>

<?php include "./pc/view/footer.inc.htm"; ?>

<link rel="stylesheet" type="text/css" href="xneditor/editor.css" />

<script src="xiunoui/async.js"></script>
<script src="xiunoui/upload.js"></script>
<script src="xneditor/editor.js"></script>
<script>

//setInterval(function() {

var editor = new $.XNEditor({textarea: 'post_message', image_upload_url:'post-upload-1.htm', image_upload_width: (<?php echo $conf['upload_image_width']; ?> - 40), file_upload_url:'post-upload-0.htm'});

var jform = $('#post_create_form');
var jinput = jform.find('input');
var jmessage = $('#post_message');
var jsubmit = jform.find('button').filter('[type="button"]');

var tid = <?php echo $tid; ?>;

jsubmit.off('click').on('click', function() {
	
	if(!jmessage.val()) {
		editor.jeditor.popover('请输入内容');
		editor.focus();
		return false;
	}
	
	jsubmit.button('loading');
	var postdata = jform.serializeObj();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.button('回帖成功');
			setTimeout(function() {editor.clear(); window.location='thread-'+tid+'.htm';}, 1000);
			return;
		} else if(code == 2) {
			jmessage.popover(message).focus();
		} else {
			$.alert(message);
		} 
		jsubmit.button('reset');
	});
	return false;
});
//}, 1000);
</script>